function dt = save2json(dt,JSON)

% Saves images from dt structures as a JSON file
%
%Example:
%
% dt = multiDcm('HUTCHESON_NATHAN/IM-0001*.dcm');
% save2json(dt,'lixo.js')
%
%Jonas ALmeida April 2012

if nargin<2
    JSON='dcmData.js';
end

if 0
im='dcm.im=[';
L=length(dt.im);
for i=1:L
    imi='[';
    [n,m]=size(dt.im{i});
    for j=1:m
        imi=[imi,strrep(mat2str(dt.im{i}(:,j)'),' ',','),','];
    end
    if i<L
        imi=[imi,'],'];
    else
        imi=[imi,']'];
    end
    im=[im,imi];
    disp([num2str(i),'/',num2str(L)]);
end
im=[im,']'];
fid = fopen(JSON,'w');
fprintf(fid,'%s',im);
fclose(fid);
end

if 1
fid = fopen(JSON,'w');
fprintf(fid,'%s','dcm.im=[');
L=length(dt.im);
for i=1:L
    fprintf(fid,'%s','[');
    [n,m]=size(dt.im{i});
    for j=1:m
        fprintf(fid,'%s',strrep(mat2str(dt.im{i}(:,j)'),' ',','));
        if j<m
            fprintf(fid,'%s',',');
        end
    end
    if i<L
        fprintf(fid,'%s','],');
    else
        fprintf(fid,'%s',']');
    end
    disp([num2str(i),'/',num2str(L)]);
end
fprintf(fid,'%s',']');
fclose(fid);
end




